import request from "@/utils/request";

const FEEDBACK_API_URL = import.meta.env.VITE_VERSION_API_URL || "";

// 提交反馈
export function submitFeedback(feedbackData) {
  return request({
    url: `${FEEDBACK_API_URL}/api/feedback`,
    method: "POST",
    data: {
      title: feedbackData.title,
      content: feedbackData.content,
      contactInfo: feedbackData.contactInfo,
      device: feedbackData.device,
      appVersion: feedbackData.appVersion,
      screenshots: feedbackData.screenshots,
      userId: feedbackData.userId,
    },
  });
}

// 获取反馈列表
export function getFeedbackList(params = {}) {
  return request({
    url: `${FEEDBACK_API_URL}/api/feedback`,
    method: "GET",
    data: {
      page: params.page || 1,
      limit: params.limit || 10,
      status: params.status,
      userId: params.userId,
    },
  });
}

// 获取反馈详情
export function getFeedbackDetail(feedbackId) {
  return request({
    url: `${FEEDBACK_API_URL}/api/feedback/${feedbackId}`,
    method: "GET",
  });
}

// 获取用户所有反馈
export function getUserFeedbacks(userId) {
  return request({
    url: `${FEEDBACK_API_URL}/api/feedback`,
    method: "GET",
    data: { userId },
  });
}

// 删除反馈
export function deleteFeedback(feedbackId) {
  return request({
    url: `${FEEDBACK_API_URL}/api/feedback/${feedbackId}`,
    method: "DELETE",
  });
}
